home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 September / LiquidLibrary 2005 Sep - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_l2img.ps < prev    next >
Text File  |  2003-01-03  |  5KB  |  175 lines

  1. %    Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Emulate the Level 2 dictionary-based image operator in Level 1,
  7. % except for Interpolate (ignored) and MultipleDataSources = true;
  8. % also, we require that the data source be either a procedure of a
  9. % particular form or a stream, not a string or a general procedure.
  10.  
  11. % pdf2ps copies the portion of this file from %BEGIN to %END if Level 1
  12. % compatible output is requested.
  13.  
  14. /currentglobal where
  15.  { pop currentglobal { setglobal } true setglobal }
  16.  { { } }
  17. ifelse
  18.  
  19. /packedarray where
  20.  { pop }
  21.  { /packedarray { array astore readonly } bind def }
  22. ifelse
  23.  
  24. %BEGIN
  25.  
  26. 11 dict /.csncompdict 1 index def begin
  27.   /DeviceGray { 1 /setgray load } bind def
  28.   /DeviceRGB { 3 /setrgbcolor load } bind def
  29.   /DeviceCMYK { 4 /setcmykcolor load } bind def
  30.   /Indexed
  31.    { dup 1 index 1 get //.csncompdict exch get exec
  32.         % Stack: [/Indexed base hival map] ncomp basesetcolor
  33.      3 -1 roll 3 get mark 3 1 roll
  34.         % Stack: ncomp -mark- basesetcolor map
  35.      dup type /stringtype eq
  36.       {  { -
  37.         { exch round cvi get 255 div
  38.         }
  39.        -
  40.         { exch round cvi 3 mul 2 copy 2 copy get 255 div
  41.           3 1 roll 1 add get 255 div
  42.           4 2 roll 2 add get 255 div
  43.         }
  44.         { exch round cvi 4 mul 2 copy 2 copy 2 copy get 255 div
  45.           3 1 roll 1 add get 255 div
  46.           4 2 roll 2 add get 255 div
  47.           5 3 roll 3 add get 255 div
  48.         }
  49.      }
  50.     4 index get aload pop counttomark -1 roll
  51.       }
  52.       { /exec load 3 -1 roll
  53.         % Stack: -mark- mapproc --exec-- basesetcolor
  54.       }
  55.      ifelse .packtomark cvx
  56.      exch pop 1 exch
  57.    } bind def
  58.   /Separation
  59.    { dup 2 index //.csncompdict exch get exec
  60.         % Stack: [/Separation name alt xform] ncomp altsetcolor
  61.      3 -1 roll 3 get /exec load 3 -1 roll 3 array astore readonly cvx
  62.      exch pop 1 exch
  63.    } bind def
  64.     % Substitute device spaces for CIE spaces.
  65.   /CIEBasedA /DeviceGray load def
  66.   /CIEBasedABC /DeviceRGB load def
  67.   /CIEBasedDEF /DeviceRGB load def
  68.   /CIEBasedDEFG /DeviceCMYK load def
  69. end
  70.  
  71. /.packtomark { counttomark packedarray exch pop } bind def
  72.  
  73. /.csinextbits        % - .csinextbits <bits>
  74.             % Uses b, nnb, i, row, mask, BitsPerComponent;
  75.             % sets b, nnb, i.
  76.  { /nnb nnb BitsPerComponent add
  77.     { dup 0 le { exit } if
  78.       /b b 8 bitshift row i get add def
  79.       /i i 1 add def  8 sub
  80.     }
  81.    loop def
  82.    b nnb bitshift mask and
  83.  } bind def
  84.  
  85. % Note that the ColorSpace key must be present in the image dictionary.
  86. /.colorspaceimage        % <imagedict> .colorspaceimage -
  87.  { save exch
  88.    dup length 15 add dict begin { cvlit def } forall
  89.    ColorSpace dup dup type /nametype ne { 0 get } if
  90.    .csncompdict exch get exec
  91.      /setpixelcolor exch def  /ncomp exch def  pop
  92.    /row ncomp BitsPerComponent mul Width mul 7 add 8 idiv string def
  93.       /mask 1 BitsPerComponent bitshift 1 sub def
  94.       /nextbits BitsPerComponent 8 eq
  95.        { { row i get /i i 1 add def } }
  96.        { /.csinextbits load }
  97.       ifelse def
  98.       /nextpixel mark 0 2 ncomp 1 sub 2 mul
  99.        { /nextbits cvx exch
  100.      Decode exch 2 getinterval
  101.      dup aload pop exch sub
  102.      dup mask eq { pop } { mask div /mul load 3 -1 roll } ifelse
  103.      0 get dup 0 eq { pop } { /sub load 3 -1 roll } ifelse
  104.        }
  105.       for
  106.       /setpixelcolor load dup type /operatortype ne { /exec load } if
  107.       .packtomark cvx def
  108.       /readrow
  109.         /DataSource load dup type
  110.         dup /arraytype eq exch /packedarraytype eq or
  111.     {    % Must be { <file> <string> ... }
  112.       aload length 1 add array /pop load exch astore
  113.       dup 1 row put cvx
  114.     }
  115.     { pop
  116.         % Adobe requires readstring to signal an error if given
  117.         % an empty string.  Work around this nonsense here.
  118.           row length 0 eq
  119.        { { } }
  120.        { { DataSource row readstring pop pop } }
  121.       ifelse
  122.     }
  123.       ifelse def
  124.       ImageMatrix matrix invertmatrix concat
  125.       /imat matrix def
  126.       0 1 Height 1 sub
  127.        { imat 5 3 -1 roll neg put
  128.      readrow
  129.      /b 0 def  /nnb 0 def  /i 0 def
  130.      0 1 Width 1 sub
  131.       { imat 4 3 -1 roll neg put nextpixel
  132.         1 1 true imat {<80>} imagemask
  133.       }
  134.      for
  135.        }
  136.       for
  137.    end restore
  138.  } bind def
  139.  
  140. %END
  141. exec
  142. currentfile closefile
  143.  
  144. % Patch for testing.
  145. /.cincompdict 3 dict begin
  146.   1 { {0 1} {/DeviceGray} } def
  147.   3 { {0 1 0 1 0 1} {/DeviceRGB} } def
  148.   4 { {0 1 0 1 0 1 0 1} {/DeviceCMYK} } def
  149. currentdict end def
  150. /.imagekeys [
  151.   /Decode /DataSource /ImageMatrix /BitsPerComponent /Height /Width
  152. ] def
  153. /colorimage        % <width> <height> <bits/comp> <matrix>
  154.             %   <datasrc> false <ncomp> colorimage -
  155.  { 1 index { /colorimage load /rangecheck signalerror } if exch pop
  156.    //.cincompdict exch get exec
  157.    7 dict begin /ColorSpace exch cvlit def
  158.    .imagekeys { exch cvlit def } forall
  159.    currentdict end .colorspaceimage
  160.  } bind odef
  161. /image
  162.  { dup type /dicttype ne
  163.     { 7 dict begin /ColorSpace /DeviceGray def [0 1] 
  164.       .imagekeys { exch cvlit def } forall
  165.       currentdict end
  166.     }
  167.     { dup length 1 add dict .copydict dup /ColorSpace currentcolorspace put
  168.     }
  169.    ifelse
  170.    .colorspaceimage
  171.  } bind odef
  172.  
  173. exec
  174.